package com.tqfframe.common.init;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @Author: 唐祺峰
 * @Date: 2022/2/15 0015 10:15
 * @Version 1.0
 */
@Component
public class TestApplicationRunner implements ApplicationRunner, DisposableBean {

    private final ApplicationContext applicationContext;

    public TestApplicationRunner(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }

    @Override
    public void destroy() throws Exception {

    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        System.out.println(applicationContext);
        Map<String, TestInitializer> initializerMap= applicationContext.getBeansOfType(TestInitializer.class);
        for(Map.Entry<String, TestInitializer> entry:initializerMap.entrySet()){
            entry.getValue().init();
        }
    }
}
